#ifndef DATAREADER_H
#define DATAREADER_H

#include <QObject>
#include <QMainWindow>
#include <QtWidgets>
#include <QtCharts>
#include <QTimer>
#include <QMessageBox>
#include "serialportmanage.h"
#include "sqlitemanage.h"

// 数据类型枚举
enum DataType {
    LIGHT,
    TEMPERATURE,
    HUMIDITY
};

// 数据点结构 - 包含三种类型的数据
struct DataPoint {
    qreal x;
    qreal light;
    qreal temperature;
    qreal humidity;
};

class DataReader : public QObject
{
    Q_OBJECT
public:
    explicit DataReader(const SerialConfig &config,QObject *parent = nullptr);
    ~DataReader();
    bool startReading();
    void stopReading();
    SerialConfig config() const;


signals:
    void dataReady(const DataPoint &data);
    void errorOccurred(const QString &error);
    void dataStored(int deviceId, const DataPoint &point);

private slots:
    void readData();
    void parseData(const QByteArray &data);
    void handleError(QSerialPort::SerialPortError error);

private:
    SerialConfig m_config;
    QSerialPort *m_serialPort;
    SqliteManage *m_pSqliteManage;
};

#endif // DATAREADER_H
